#include "common.h"
#include "MangoFishGame.h"

// Constructor
MangoFishGame::MangoFishGame() {

	// Set display mode
	mangoWindow = CL_DisplayWindow ("MangoFish", 1024, 768);
	
	alive = true;
	current_world = new World(RESOURCES_PATH "/artwork/back.png");
 
	loadGraphics();
//	mousePress = CL_Mouse::sig_key_down().connect(this, &MangoFishGame::handleMousePress);
	keyboardPress = CL_Keyboard::sig_key_down().connect(this, &MangoFishGame::processInput);
}

// Destructor
MangoFishGame::~MangoFishGame() {
	// Delete the surfaces
	delete current_world;
}

void MangoFishGame::loadGraphics() {
}

void MangoFishGame::run() {

	while (alive) {
		
		// Drawing function
		paint();

		// Double buffering
		CL_Display::flip();

		// Sleep for this much
		CL_System::sleep(10);
		CL_System::keep_alive();
	}
}

void MangoFishGame::processInput(const CL_InputEvent &key) {
	if (key.id == CL_KEY_UP) {
		std::cout << "Up Button Pressed" << std::endl;
	}

	else if (key.id == CL_KEY_DOWN) {
		std::cout << "Down Button Pressed" << std::endl;
	}

	else if (key.id == CL_KEY_LEFT) {
		std::cout << "Left Button Pressed" << std::endl;
	}

	else if (key.id == CL_KEY_RIGHT) {
		std::cout << "Right Button Pressed" << std::endl;
	}

	else if (key.id == CL_KEY_ESCAPE) {
		std::cout << "Quitting MangoFish... bye!" << std::endl;
		alive = false;
	}

	else {
		std::cout << "Unknown key pressed :s" << std::endl;
	}
}

void MangoFishGame::paint() {
	// Paint the current world. 
	current_world->paint();
}

void MangoFishGame::handleMousePress(const CL_InputEvent &key) {

	// Since a clicked happened, get the screen coordinates of the mouse
	int x = key.mouse_pos.x, y = key.mouse_pos.y;
}
